/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.model;

import com.db.SqlManager;
import com.exception.DataException;
import com.javabeans.DetalleDocente;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 *
 * @author Administrador
 */
public class AdminDetalleDocente implements DetalleDocenteManager{
    private Connection c;
    public AdminDetalleDocente(Connection c){
        this.c = c;
    }
    @Override
    public void saveDetalleDocente(DetalleDocente dd) throws DataException {
        PreparedStatement preSt = null;
        String query;
        try{
            query="INSERT INTO DETALLE_DOCENTE VALUES("+dd.getIdDetalleDocente();
            query+= ", "+dd.getIdPais();
            query+= ", "+dd.getIdCiudad();
            query+= ", '"+dd.getLocalidad().toUpperCase();
            query+= "', "+dd.getIdCategoria()+")";            
            preSt = c.prepareStatement(query);
            preSt.executeUpdate();
        }catch(SQLException ex){
            throw new DataException("AdminDetalleDocente -> saveDetalleDocente(DetalleDocente dd) "+ex.getMessage());
        }finally{
            SqlManager.closePreSt(preSt);
        }
    }
    @Override
    public void updateDetalleDocente(DetalleDocente dd) throws DataException {
        PreparedStatement preSt = null;
        try{
            String query = "UPDATE DETALLE_DOCENTE SET IDPAIS = "+dd.getIdPais();
            query+= ", IDCIUDAD = "+dd.getIdCiudad();
            query+= ", LOCALIDAD = '"+dd.getLocalidad();
            query+= "', IDCATEGORIA = "+dd.getIdCategoria();
            query+= " WHERE IDDETALLE_DOCENTE="+dd.getIdDetalleDocente();            
            preSt = c.prepareStatement(query);
            preSt.executeUpdate();
        }catch(SQLException ex){
            throw new DataException(" AdminDetalleDocente -> updateDetalleDocente(DetalleDocente dd) e = "+ex.getMessage());
        }finally{
            SqlManager.closePreSt(preSt);
        }
    }
}
